#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int d[N],v[N],p[N],zero;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t,n,m,l,vv,res1,ma,res2;
    cin>>t;
    for(int task=0;task<t;task++){
        ma=0x3f3f3f3f;
        cin>>n>>m>>l>>vv;
        res1=0;
        res2=m;
        for(int i=0;i<n;i++){
            cin>>d[i]>>v[i]>>zero;
            if(v[i]>vv){
                ma=max(d[i],ma);
                res1++;
            }
        }for(int i=0;i<m;i++){
            cin>>p[i];
            if(p[i]>ma)res2--;
        }if(res1)res2--;
        cout<<res1<<' '<<res2<<endl;
    }
}
